package com.open.companymessage.company.controller;


import com.open.capacity.common.model.CompanyActive;
import com.open.capacity.common.model.SysCompany;
import com.open.capacity.common.util.PageUtil;
import com.open.capacity.common.web.PageResult;
import com.open.capacity.common.web.Result;
import com.open.companymessage.company.service.CompanyService;
import com.open.companymessage.company.vo.UserCompany;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/company")
public class CompanyInformationController {
    @Autowired
    private CompanyService companyService;

    //    添加公司信息
    @PostMapping("/addCompany")
    public Result addCompany(@RequestBody UserCompany userCompany,@RequestParam("access_token") String token) {
        return companyService.addCompany(userCompany, token);
    }

    //    修改公司信息
    @PostMapping("/updateCompany")
    public Result updateCompany(@RequestBody SysCompany sysCompany) {
        return companyService.updateCompany(sysCompany);
    }

    //    模糊查询
    @PostMapping("/selectCompany")
    public PageResult selectAll(@RequestParam Map<String, Object> map) {
        PageUtil.pageParamConver(map,true);
        List<SysCompany> list = companyService.selectCompany(map);
        return PageResult.<SysCompany>builder().code(0).
                data(list).count((long) list.size()).build();
    }

    //公司信息删除
    @PostMapping("/deleteCompany/{id}")
    public Result deleteCompany(@PathVariable Long id) {
        return companyService.deleteCompany(id);
    }

    /**
     * 公司与活动关联
     * @param map
     * @return
     */
    @PostMapping("/selectCompanyActive")
    public PageResult selectCompanyActive(@RequestParam Map<String,Object> map){
        List<CompanyActive> list = companyService.selectCompanyActive(map);
        PageUtil.pageParamConver(map,true);
//        分页
        return PageResult.<CompanyActive>builder().code(0).
        data(list).count((long)list.size()).build();
    }

    /**
     * 添加公司id和活动id
     * @param companyActive
     * @return
     */
    @PostMapping("/insertCompanyID")
    public Result insertCompanyID(@RequestBody CompanyActive companyActive){
        return companyService.insertCompanyID(companyActive);
    }

    /**
     * 删除company_active表数据
     * @param companyActive
     * @return
     */
    @PostMapping("/deleteCompanyActiveId")
    public Result deleteCompanyActiveId(@RequestBody CompanyActive companyActive){
        return companyService.deleteCompanyActiveId(companyActive);
    }
}
